<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
    <script type="text/javascript" src="./script/aui-sharebox.js" ></script>
</head>
<body>

    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>升级</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>

    <div class="user-invite-uplevel" id="list">

        <div class="user-invite-uplevel-t">
            <p>您的直属<img src="image/gril.png">***</p>
            <p>已达升到<span>1级</span>标准,</p>
            <p>您批准升级后,</p>
            <!-- <p>将从您的赚石中扣除<i>888</i></p> -->
        </div>
        <div class="user-invite-uplevel-d">
            您当前赚石
            <p>100000</p>
        </div>

    </div>

    <div class="btn-1 mt60" tapmode onclick="user_invite_pay()">升级</div>


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/template" id="template">
    <div class="user-invite-uplevel-t">
        <p>您的直属<img src="{{=it.avatar}}">{{=it.name}}</p>
        <p>已达升到<span>{{=it.upgrade_info.level_to}}级</span>标准,</p>
        <p>您批准升级后,</p>
        <!-- <p>将从您的赚石中扣除<i>{{=it.upgrade_info.integral}}</i></p> -->
    </div>
    <div class="user-invite-uplevel-d">
        您当前赚石
        <p id="integral">100000</p>
    </div>
</script>
<script type="text/javascript">

    apiready = function(){
        userid = api.pageParam.id;
        loadData(userid);
    }
    

    function loadData(userid){

            // 进度提示框
            api.showProgress({
              title: '努力加载中...',
              text: '请稍等...',
              modal: false
          });

            var token = $api.getStorage('token');
            api.ajax({
                url: webAddress + '/api/user/list/invite/'+userid+'/show',
                method: 'get',
                data: {
                    values: {
                    },
                },
                headers: {
                    Authorization: 'Bearer ' + token,
                    Accept: 'application/json',
                },
            },function(ret, err){
              if (ret) {
                // alert( JSON.stringify( ret ) );
                // 关闭上拉加载控件
                api.hideProgress();
                // 关闭下拉刷新控件
                // api.refreshHeaderLoadDone();
                if (ret.data) {
                    templateFun(ret.data);
                    needIntegral = ret.data.upgrade_info.integral;
                }
            } else {
              api.hideProgress();
              // alert( JSON.stringify( err ) );
          }
      });
        }

    // 模板赋值函数
    function templateFun(data){

      var template = $api.byId('template');
      var dotFn = doT.template(template.innerHTML);
      var html = dotFn(data);
      var list = $api.byId('list');
      $api.html(list, html);
      // 获取用户个人赚石
      loadIntegral();
  }

// 获取当前用户个人赚石
function loadIntegral(){
    var token = $api.getStorage('token');
    api.ajax({
      url: webAddress + '/api/auth/info',
      method: 'get',
      data: {
        values: {
        },
    },
    headers: {
        Authorization: 'Bearer ' + token,
        Accept: 'application/json',
    },
},function(ret, err){
  if (ret) {
        // alert( JSON.stringify( ret ) );
        integral = ret.data.integral;
        $('#integral').html(integral);
    } else {
        // alert( JSON.stringify( err ) );
        return false;
    }
});
}

// 去支付
function user_invite_pay() {
    api.openWin({
        name: 'user_invite_uplevel_password',
        url: './user_invite_uplevel_password.html',
        pageParam: {
            id: userid,
            needIntegral: needIntegral,
            integral: integral,
        }
    });
}

function closeWin(){
    api.closeWin({
    });
}
</script>
</html>